package com.jeesite.modules.dp.web.zhibiao;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.dp.entity.zhibiao.DpIndicator;
import com.jeesite.modules.dp.service.zhibiao.DpIndicatorService;

/**
 * 指标管理Controller
 * @author hancing
 * @version 2024-12-05
 */
@Controller
@RequestMapping(value = "${adminPath}/dp/zhibiao/dpIndicator")
public class DpIndicatorController extends BaseController {

	@Autowired
	private DpIndicatorService dpIndicatorService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DpIndicator get(String id, boolean isNewRecord) {
		return dpIndicatorService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("dp:zhibiao:dpIndicator:view")
	@RequestMapping(value = {"list", ""})
	public String list(DpIndicator dpIndicator, Model model) {
		model.addAttribute("dpIndicator", dpIndicator);
		return "modules/dp/zhibiao/dpIndicatorList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("dp:zhibiao:dpIndicator:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DpIndicator> listData(DpIndicator dpIndicator, HttpServletRequest request, HttpServletResponse response) {
		dpIndicator.setPage(new Page<>(request, response));
		Page<DpIndicator> page = dpIndicatorService.findPage(dpIndicator);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("dp:zhibiao:dpIndicator:view")
	@RequestMapping(value = "form")
	public String form(DpIndicator dpIndicator, Model model) {
		model.addAttribute("dpIndicator", dpIndicator);
		return "modules/dp/zhibiao/dpIndicatorForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("dp:zhibiao:dpIndicator:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DpIndicator dpIndicator) {
		dpIndicatorService.save(dpIndicator);
		return renderResult(Global.TRUE, text("保存指标成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("dp:zhibiao:dpIndicator:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DpIndicator dpIndicator) {
		dpIndicatorService.delete(dpIndicator);
		return renderResult(Global.TRUE, text("删除指标成功！"));
	}
	
}